﻿// CDialogAddFriend.cpp: 实现文件
//

#include "pch.h"
#include "ChatSystem.h"
#include "afxdialogex.h"
#include "CDialogAddFriend.h"


// CDialogAddFriend 对话框

IMPLEMENT_DYNAMIC(CDialogAddFriend, CDialogEx)

CDialogAddFriend::CDialogAddFriend(int userid, CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_ADDFRIEND, pParent)
	, friend_tel(_T(""))
	, userid_(userid)
{

}

CDialogAddFriend::~CDialogAddFriend()
{
}

void CDialogAddFriend::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_ADDFRIEND, friend_tel);
}


BEGIN_MESSAGE_MAP(CDialogAddFriend, CDialogEx)
	ON_BN_CLICKED(IDC_BUTADDFRIEND, &CDialogAddFriend::OnBnClickedButaddfriend)
END_MESSAGE_MAP()


// CDialogAddFriend 消息处理程序


void CDialogAddFriend::OnBnClickedButaddfriend()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);
	if (friend_tel.IsEmpty()) {
		MessageBox("输入内容不能为空");
		return;
	}
	TcpSvr* ts = TcpSvr::GetInstance();
	if (ts == NULL) {
		MessageBox("获取TCP指针失败,请过一会儿再试");
		return;
	}
	//组织消息并发送
	ChatMsg cm;
	cm.msg_type_ = AddFriend;
	cm.userid_ = userid_;
	cm.json_msg_["telnum"] = friend_tel.GetString();
	std::string msg;
	cm.GetMsg(&msg);
	//3.发送数据
	ts->Send(msg);
	CDialog::OnCancel();
}
